
import { _decorator, Component, Graphics } from 'cc';
import { GameConfig } from '../gameConfig';
import { FogGoGame } from '../gamecore/fogGoGame';
const { ccclass, property } = _decorator;

//花棋盘上的线
@ccclass('BoardLine')
export class BoardLine extends Component {
    private gameSize = 19;//棋盘大小，9*9 13*13 19*19 只有这三种大小

    private boradWight = 300; //线与线距离

    private fogGO: FogGoGame; //

    onLoad() {
        this.gameSize = GameConfig.instance.gameSize;
        this.boradWight = GameConfig.instance.boardWight;
    }

    start () {
        const space = this.boradWight / (this.gameSize - 1);
        const g = this.getComponent(Graphics);
        //画竖线
        for (let i = 0; i < this.gameSize - 1; i += 1) {
            g.moveTo((space * i * 2) - this.boradWight, -this.boradWight);
            g.lineTo((space * i * 2) - this.boradWight, this.boradWight);
        }
        g.moveTo(this.boradWight, -this.boradWight);
        g.lineTo(this.boradWight, this.boradWight);

        //画横线
        for (let i = 0; i < this.gameSize - 1; i += 1) {
            g.moveTo(-this.boradWight, this.boradWight - (space * i * 2));
            g.lineTo(this.boradWight, this.boradWight - (space * i * 2));
        }
        g.moveTo(-this.boradWight, -this.boradWight);
        g.lineTo(this.boradWight, -this.boradWight);
        g.stroke();
        if (this.gameSize == 19) {
            for (let i = -1; i < 2; i++) {
                for (let j = -1; j < 2; j++) {
                    g.circle(i * 200, j * 200, 5);
		            g.fill();
                }
            }
        }
        g.stroke();

        this.fogGO = new FogGoGame(this.gameSize);
    }
}
